import { createRouter, createWebHistory,createWebHashHistory  } from 'vue-router'
import { routerList } from './routeList'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { useRouterStore } from '@/stores/router'

function buildRouter() {
    NProgress.configure({
        showSpinner: false,
    })

    const router = createRouter({
        history: createWebHashHistory(),
        routes: routerList,
    })

    const routerStore = useRouterStore()

    router.beforeEach((to, from, next) => {
        NProgress.start()
        next()

        routerStore.currentPath = to.path
    })
    router.afterEach((to, from, next) => {
        NProgress.done()
    })

    return router
}

export { buildRouter }
